﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI;
using TA.DotNetUtils;

namespace TA.Turbo.Controls
{
	/// <summary>
	/// The container for all page buttons in a Repeater.
	/// </summary>
	public class RepeaterPagerContainer : BaseRepeaterControl
	{
		internal RepeaterPagerContainer(Repeater rpt, string cssClass, PagerPosition position)
			: base(rpt)
		{
			this._cssClass = cssClass;
			this._position = position;

			this.Controls.Add(new RepeaterPageButtonFirst(this.Repeater));
			this.Controls.Add(new RepeaterPageButtonPrevious(this.Repeater));
			this.Controls.Add(new RepeaterPageButtonPreviousGroup(this.Repeater));

			this.Controls.Add(new RepeaterPagesButtonsContainer(this.Repeater));

			this.Controls.Add(new RepeaterPageButtonNextGroup(this.Repeater));
			this.Controls.Add(new RepeaterPageButtonNext(this.Repeater));
			this.Controls.Add(new RepeaterPageButtonLast(this.Repeater));
		}
		/// <summary>
		/// Renders all the page buttons.
		/// </summary>
		/// <param name="writer"></param>
		public override void RenderControl(HtmlTextWriter writer)
		{
			int minNumPages = (int)this.Repeater.Pager.DisplayMode;

			if (this.Repeater.Pager.Size == 0 || // no pagin or ...
				this.Repeater.NumPages < minNumPages || // ... not enough pages or ...
				(this.Repeater.Pager.Position & this._position) != this._position // ... this pager is not visible
				)
				writer.AddStyleAttribute(HtmlTextWriterStyle.Display, "none");
			writer.AddAttribute(HtmlTextWriterAttribute.Class, "pager " + this._cssClass);
			writer.RenderBeginTag(HtmlTextWriterTag.Div);


			this.RenderChildren(writer);


			writer.RenderEndTag();
		}


		string _cssClass;
		PagerPosition _position;
	}
}
